﻿package mortal.game.view.mainUI.smallMap.view.render
{
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.manager.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mainUI.smallMap.view.data.*;
    import mortal.mvc.core.*;

    public class SmallMapTypeIconItem extends ToolTipSprite
    {
        private var _swf:SWFPlayer;
        private var _icon:GBitmap;
        private var _tips:String = "test";
        private var _data:SmallMapTypeIconData;
        private var _labelX:int = -1;
        private var _labelY:int = -1;

        public function SmallMapTypeIconItem()
        {
            return;
        }// end function

        public function updateData(param1:SmallMapTypeIconData) : void
        {
            if (param1.iconName != null)
            {
                if (param1.iconName.indexOf(".swf") >= 0)
                {
                    if (this._swf == null)
                    {
                        this._swf = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
                    }
                    this._swf.timeRate = 2;
                    this._swf.move(0, 0);
                    if (param1.iconName == "smallMapTeamate.swf")
                    {
                        this._swf.move(200, 200);
                    }
                    this._swf.load(param1.iconName, ModelType.NormalSwf, null);
                    this._swf.play();
                    this.addChild(this._swf);
                    this._labelX = 40;
                    this._labelY = 30;
                }
                else
                {
                    if (this._icon == null)
                    {
                        this._icon = UIFactory.gBitmap("", 0, 0, this);
                    }
                    this._icon.bitmapData = GlobalClass.getBitmapData(param1.iconName);
                    if (param1.isGrayFilter)
                    {
                        this._icon.filters = [FilterConst.colorFilter];
                    }
                    else
                    {
                        this._icon.filters = [];
                    }
                }
            }
            this._data = param1;
            if (param1.tips != null)
            {
                this._tips = param1.tips;
                this.mouseEnabled = true;
                this.mouseChildren = true;
            }
            else
            {
                this.mouseEnabled = false;
                this.mouseChildren = false;
            }
            this.x = param1.x * param1.scale - param1.width / 2;
            this.y = param1.y * param1.scale - param1.height / 2;
            return;
        }// end function

        public function get labelX() : int
        {
            if (this._labelX != -1)
            {
                return this.x - this._labelX;
            }
            return this.x - 42;
        }// end function

        public function get labelY() : int
        {
            if (this._labelY != -1)
            {
                return this.y - this._labelY;
            }
            return this.y - 16;
        }// end function

        override public function get toolTipData()
        {
            return this._tips;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.mouseEnabled = true;
            this.mouseChildren = true;
            this.doubleClickEnabled = true;
            this.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this.configEventListener(MouseEvent.DOUBLE_CLICK, this.flyToHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this._icon != null)
            {
                this._icon.dispose(param1);
                this._icon = null;
            }
            if (this._swf != null)
            {
                this._swf.dispose(param1);
                this._swf = null;
            }
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.SmallMapTypeIconClick, this._data));
            return;
        }// end function

        public function flyToHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.SmallMapTypeIconDoubleClick, this._data));
            return;
        }// end function

    }
}
